package org.bwf.study.controller;

import org.bwf.study.aop.ReturnInfo;
import org.bwf.study.util.RedisUntil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/msg/")
public class MSGController {

    @Resource
    private RedisUntil redisUntil;

    // http://localhost:8087/api/msg/?phoneNumber=13917703030
    // http://localhost:8087/api/msg/13917703030
    @GetMapping("{phoneNumber}")
    public Object RegisterMsg(@PathVariable String phoneNumber){
        String valCode = String.valueOf((int)((Math.random()*9+1)*100000));
        //发送短信
        // valCode存放到Redis
        String key = String.format("reg-%s", phoneNumber);
        redisUntil.set(key, valCode, 300);
        return new ReturnInfo(valCode);
    }

}
